package com.dbzf.controller;

import com.dbzf.controller.student.StudentServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

@WebServlet("/student/*")
public class BaseServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String url = req.getRequestURI();
        int index = url.lastIndexOf("/");
        String method = url.substring(index + 1);
        Class<StudentServlet> aClass = StudentServlet.class;
        try {
            StudentServlet studentServlet = aClass.newInstance();
            Method method1 = aClass.getDeclaredMethod(method, HttpServletRequest.class, HttpServletResponse.class);
            method1.invoke(studentServlet,req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
